/*
 * @Author: Da Kang
 * @Date: 2021-03-01 14:14:20
 * @LastEditors: Da Kang
 * @LastEditTime: 2021-07-20 09:51:55
 * @FilePath: /bd-h5-web/vue.config.js
 */
const GenerateAssetPlugin = require('generate-asset-webpack-plugin');
const configJson =
    process.env.NODE_ENV === 'testing'
        ? require('./src/config/test.json')
        : require('./src/config/prod.json');

const createConfig = function () {
    return JSON.stringify(configJson);
};
const mdConfig = function(){
    return JSON.stringify(require('./README.md'));
}

module.exports = {
    lintOnSave:false,
    css: {
        extract: false,
        loaderOptions: {
            sass: {
                prependData: `@import "@/assets/css/global.scss";`
            }
        }
    },
    devServer: {
        disableHostCheck: true, //  新增该配置项
        proxy: {
            '^/lecar-ka-service': {
                target: 'http://192.168.1.31:7777/', //192.168.30.18:7778/
                changeOrigin: true,
                secure: false
            },
            '^/ka-moot-service':{
                target: 'http://192.168.123.129:7017/',
                changeOrigin: true,
                secure: false
            }
        }
    },
    configureWebpack: config => {
        if (process.env.NODE_ENV === 'production') {
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
            config.plugins.push(
                new GenerateAssetPlugin({
                    filename: 'config.json',
                    fn: (compilation, cb) => {
                        cb(null, createConfig(compilation));
                    }
                })
            );
            config.plugins.push(
                new GenerateAssetPlugin({
                    filename: 'README.md',
                    fn: (compilation, cb) => {
                        cb(null, mdConfig(compilation));
                    }
                })
            );
        }
       
    },
    chainWebpack(config) {
        config
        // https://webpack.js.org/configuration/devtool/#development
        .when(process.env.NODE_ENV === 'development',
          config => config.devtool('source-map') //cheap-
        )
  
    }
};


